package com.mm.learn.shopping.order.vo;

import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author wdx
 * @date 2021年07月26日 16:58
 * 订单确认页需要用的数据
 */

public class OrderConfirmVo {

    //收货地址
    List<MemberAddressVo> address;

    //所有选中的购物车项
    List<OrderItemVo> items;

    //发票记录...

    //优惠券信息...
    Integer integration;

    /**
     * 防重令牌
     */
    @Getter
    @Setter
    String orderToken;

    //订单总额
    BigDecimal total;

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal(0);
        if (!CollectionUtils.isEmpty(items)) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    //应付价格
    BigDecimal payPrice;
    @Getter @Setter
    boolean stocks;

    public Integer getCount(){
        Integer i = 0 ;
        if(items!=null){
            for (OrderItemVo item : items) {
                i+=item.getCount();
            }
        }
        return i;
    }

    public List<MemberAddressVo> getAddress() {
        return address;
    }

    public void setAddress(List<MemberAddressVo> address) {
        this.address = address;
    }

    public List<OrderItemVo> getItems() {
        return items;
    }

    public void setItems(List<OrderItemVo> items) {
        this.items = items;
    }

    public Integer getIntegration() {
        return integration;
    }

    public void setIntegration(Integer integration) {
        this.integration = integration;
    }


    public BigDecimal getPayPrice() {
        return getTotal();
    }

}
